package com.koi.system.controller.login;

import com.koi.model.bo.system.SysLoginBo;
import com.koi.model.vo.system.SysLoginVo;
import com.koi.model.vo.system.SysRegisterVo;
import com.koi.system.service.login.SysLoginService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ･ᴗ･
 * @description [SysLoginController-登录接口]
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
public class SysLoginController {

    private final SysLoginService loginService;

    /**
     * @description [PC登录]
     * @author ･ᴗ･
     */
    @PostMapping("/auth/login")
    public SysLoginBo login(@Validated @RequestBody SysLoginVo loginVo) {
        return loginService.login(loginVo);
    }

    /**
     * 退出登录，调用此后端接口的时候，默认直接从携带Headers请求头中获取token值。
     * Authorization（这个key，sa-token的yml可进行配置） Bearer D0_TfFaChPxkvxghK_tabvTy5IRB9DdvQR__
     *
     * @description [退出登录]
     * @author ･ᴗ･
     */
    @GetMapping("/auth/logout")
    public String logout() {
        loginService.logout();
        return "退出成功";
    }

    /**
     * @description [PC注册]
     * @author ･ᴗ･
     */
    @PostMapping("/auth/register")
    public void register(@Validated @RequestBody SysRegisterVo registerVo) {
        loginService.register(registerVo);
    }

}
